package net.xxcxcxcx.xc_enhancedmob.skills.basics.individual.doubleedged;

import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.nbt.NbtCompound;
import net.xxcxcxcx.xc_enhancedmob.config.skill.SkillConfig;
import net.xxcxcxcx.xc_enhancedmob.skills.BaseSkill;
import net.xxcxcxcx.xc_enhancedmob.skills.Ref;
import net.xxcxcxcx.xc_enhancedmob.skills.SkillRarity;

public class ConnectionSkill extends BaseSkill {

    public ConnectionSkill(int level){super(level);}

    public ConnectionSkill(NbtCompound nbtCompound){super(nbtCompound);}

    public ConnectionSkill(){
    }

    @Override
    public SkillConfig getDefaultConfig() {
        SkillConfig skillConfig = super.getDefaultConfig();
        skillConfig.setMaxlevel(1);
        skillConfig.setMessage(getConfigMessage(skillConfig));
        return skillConfig;
    }

    @Override
    public String getConfigMessage(SkillConfig skillConfig) {
        return "自身和目标受到相同的伤害";
    }

    public SkillRarity getSkillRarity(){return SkillRarity.DoubleEdged;}

    @Override
    public boolean onAttack(MobEntity attacker, LivingEntity target, DamageSource source, Ref<Float> amount, boolean ismob, boolean remote) {
        if(amount.getValue()>0 && attacker != null && source.getSource() == attacker)
        {
            attacker.damage(DamageSource.OUT_OF_WORLD,amount.getValue());
        }
        return true;
    }

    @Override
    public boolean onDamaged(LivingEntity attacker, MobEntity target, DamageSource source, Ref<Float> amount, boolean ismob, boolean remote) {
        if(amount.getValue()>0 && attacker != null && source.getSource() == attacker && !source.isSourceCreativePlayer())
        {
            attacker.damage(DamageSource.OUT_OF_WORLD,amount.getValue());
        }
        return true;
    }
}
